
********************************************************************************************************************************
********This file replicates Table 1 (and appendix tables) and figures 1 &5 for Scruggs and Hayes Welfare Generosity Paper*****
********************************************************************************************************************************

use "/Users/thayes/Dropbox/Welfare Generosity & Inequality/data/welfare_generosity_final_data_12_1_16.dta saved"

****generates time variable counter
*gen time= _n
xtset stnum year
replace nettanfsnapminrr=69.4 if statename=="Florida" & year==1991 & nettanfsnapminrr==.

*****impute missing values for top1 for 1983, 1984, 1985
for num 1/56: ipolate newtop1 year if stnum==X, gen(newtop1_5X)
for num 1/56: ipolate newtop10 year if stnum==X, gen(newtop10_5X)
gen newtop1i=newtop1_51 if stnum==1
gen newtop10i=newtop10_51 if stnum==1
for num 2/56: replace newtop1i=newtop1_5X if stnum==X
for num 2/56: replace newtop10i=newtop10_5X if stnum==X
drop newtop1_51-newtop10_556

drop if year>2010 | year<1976
for var netrrcwed nettanfsnaprr nettanfsnapmin marketgini postgini nonwhite pop65 uniondense: replace X=X*100
**************spending per capita measures
gen realspendpc=totspendpc/cpi2010
replace realspendpc=(realspendpc[_n-1] + realspendpc[_n+1])/2 if year==2001
replace realspendpc=(realspendpc[_n-1] + realspendpc[_n+1])/2 if year==2003

label var realspendpc "State Spending per capita, 2010 prices" 
gen lnrpcdinc=ln(rpcdinc)
gen lnrealspendpc=ln(realspendpc)

**********************************
****This creates figure 1*********
**********************************
gen top180=newtop1i[_n-30] if year==2010

twoway (scatter newtop1i top180, mlab(stname) mlabs(vsmall) m(i)) (lfit newtop1i top180), ytitle("Top 1% Share (2010)") xtitle("Top 1% Share (1980)") xscale(range(4(2)14)) legend(off) graphregion(color(white)) bgcolor(white)
**********************************

******************************************************
******************Figure 5****************************
******scatter of basic relationship*******************
******************************************************

for var nettanfrr nettanfsnaprr netrrcwed newtop1i: gen Xd=X-X[_n-1] if stnum==stnum[_n-1]

graph twoway (scatter netrrcwed1 newtop1i) (lfitci netrrcwed1 newtop1i), ytitle(Net UI RR) xtitle("Percent to Top 1%") title("Unemployment Insurance RR") legend(off) graphregion(color(white)) name(a)
graph twoway (scatter nettanfsnaprr1 newtop1i) (lfitci nettanfsnaprr1 newtop1i), ytitle(Net TANF RR) xtitle("Percent to Top 1%") title("Social Assistance RR") legend(off) graphregion(color(white)) name(b)

graph combine a b, r(1) graphregion(color(white)) scheme(s1mono) altshrink 

graph display, ysize(5) xsize(10)

*****Generating variables
sort stnum year
eststo clear
set matsize 10000
gen taxui=(year==1987)
gen welrefo=(year==1997)
gen stim=(year==2009)
gen new9099=newtop10i-newtop1i
gen netrrcwed1=netrrcwed
gen nettanfsnaprr1=nettanfsnaprr

********Table 1********
*** Table is the lagged difference model, with the right side lagged one period. *********
eststo clear
xtreg d.netrrcwed1 dl.newtop1i taxui ,  fe vce(cluster stnum)
eststo
xtreg  d.netrrcwed1 dl.newtop1i dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg d.nettanfsnaprr1 dl.newtop1i welre,  fe vce(cluster stnum)
eststo
xtreg d.nettanfsnaprr1 dl.newtop1i dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.gendef welre,  fe vce(cluster stnum)
eststo
***note that for esttab you must re-write the file destination to create file for table*****
esttab using "\Users\thayes\Dropbox\Welfare Generosity & Inequality\data\difftables.rtf", replace label se starlevels(* .10 ** .05 *** .01) scalars(N )


*********************************************
*****Appendix Alternative Specifications*****
*********************************************
**Error Correction Framework***Appendix C1
***UIRR****
xtset stnum year
eststo clear
**simple top 1
qui xtpmg d.netrrcwed1 d.newtop1i dl.reserveratio, lr(l.netrrcwed  l.newtop1i l2.reserveratio) dfe cluster(stnum) replace
eststo
***full top 1 
qui xtpmg d.netrrcwed1 d.newtop1i d.bfavg d.repcont ld.elect1 d.lnrpcdinc d.nonwhite d.pop65 d.uniondense dl.reserveratio, lr(l.netrrcwed  l.newtop1i l.bfavg l.repcont l.lnrpcdinc l.nonwhite l.pop65 l.uniondense l2.reserveratio) dfe cluster(stnum) replace
eststo
*********SARR**********
**simple top 1
qui xtpmg d.nettanfsnaprr1 d.newtop1i d.gendef, lr(l.nettanfsnaprr l.newtop1i l.gendef) dfe cluster(stnum) replace
eststo
***full top 1
qui xtpmg d.nettanfsnaprr1 d.newtop1i d.bfavg d.repcont ld.elect1 d.lnrpcdinc d.nonwhite d.pop65 d.uniondense d.gendef, lr(l.nettanfsnaprr  l.newtop1i l.bfavg l.repcont l.lnrpcdinc l.nonwhite l.pop65 l.uniondense l.gendef) dfe cluster(stnum) replace
eststo
esttab using "\Users\thayes\Dropbox\Welfare Generosity & Inequality\data\appendixtable1.rtf", replace label se starlevels(* .10 ** .05 *** .01) scalars(N )

************************************************
*******Lagged and Difference Models
************************************************

*******Difference Models, w/o RHS lag *****Appendix Table C2
eststo clear
xtreg d.netrrcwed1 d.newtop1i taxui, fe vce(cluster stnum)
eststo
xtreg  d.netrrcwed1 d.newtop1i d.bfavg d.repcont d.elect1 d.lnrpcdinc d.nonwhite d.pop65 d.uniondense d.reserveratio taxui , fe vce(cluster stnum) 
eststo
xtreg d.nettanfsnaprr1 d.newtop1i welre, fe vce(cluster stnum)
eststo
xtreg d.nettanfsnaprr1 d.newtop1i d.bfavg d.repcont d.elect1 d.lnrpcdinc d.nonwhite d.pop65 d.uniondense d.gendef welre, fe vce(cluster stnum)
eststo
esttab using "\Users\thayes\Dropbox\Welfare Generosity & Inequality\data\difftablesappendix2.rtf", replace label se starlevels(* .10 ** .05 *** .01) scalars(N )

********Lagged Models********Appendix Table C3
eststo clear
xtreg netrrcwed1 l.newtop1i taxui, fe vce(cluster stnum)
eststo
xtreg netrrcwed1 l.newtop1i l.bfavg l.repcont l.elect1 l.lnrpcdinc l.nonwhite l.pop65 l.uniondense l.reserveratio taxui, re vce(cluster stnum) 
eststo
xtreg nettanfsnaprr1 l.newtop1i welre,  fe vce(cluster stnum)
eststo
xtreg nettanfsnaprr1 l.newtop1i l.bfavg l.repcont l.elect1 l.lnrpcdinc l.nonwhite l.pop65 l.uniondense l.gendef welre stim, fe vce(cluster stnum)
eststo
esttab using "\Users\thayes\Dropbox\Welfare Generosity & Inequality\data\lagtablesappendix2.rtf", replace label se starlevels(* .10 ** .05 *** .01) scalars(N )


******Neighbor State Average of Top1% (for appendix)
******Neighbor State Average of Top1%, Weighted by State Population (for appendix)***Appendix Table C4

*** Table is the lagged difference model, with the right side lagged one period. *********
eststo clear
xtreg d.netrrcwed1 dl.newtop1i taxui ,  fe vce(cluster stnum)
eststo
xtreg  d.netrrcwed1 dl.newtop1i dl.nt1ineighave2 dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg d.nettanfsnaprr1 dl.newtop1i welre,  fe vce(cluster stnum)
eststo
xtreg d.nettanfsnaprr1 dl.newtop1i dl.nt1ineighave2 dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.gendef welre stim,  fe vce(cluster stnum)
eststo
esttab using "/Users/thayes/Dropbox/Welfare Generosity & Inequality/data/difftablesappendix.rtf", replace label se starlevels(* .10 ** .05 *** .01) scalars(N )


/*** Recipiency rates***/
/*** These measure the number of UI payments divided by the reported unemployed in the state***/
/*
/*graphing states recipiency rates*/
levels stname, local(statename) 
foreach s of local statename {
scatter ruicue uicompue uicompstue year if year>1975 & stname=="`s'", c(l l l) title("`s'")
graph save receipt`s'
}
*/

***Models with UI recipiency rates****Appendix Table C5
replace uicompstue=uicompstue*100
gen receivedrr=netrrcwed*uicompstue/100

replace uicompue=uicompue*100
gen receivedrrtot=netrrcwed*uicompue/100

eststo clear
xtreg d.uicompstue dl.newtop1i taxui ,  fe vce(cluster stnum)
eststo
xtreg  d.uicompstue dl.newtop1i dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg  d.uicompstue dl.newtop1i dl.nt1ineighave2 dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg d.receivedrr dl.newtop1i taxui ,  fe vce(cluster stnum)
eststo
xtreg  d.receivedrr  dl.newtop1i dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg  d.receivedrr  dl.newtop1i dl.nt1ineighave2 dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
esttab using "/Users/thayes/Dropbox/Welfare Generosity & Inequality/data/uireceipttables.rtf", replace label se starlevels(* .10 ** .05 *** .01) scalars(N )


****Appendix Table C6
eststo clear
xtreg d.uicompue dl.newtop1i taxui ,  fe vce(cluster stnum)
eststo
xtreg  d.uicompue dl.newtop1i dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg  d.uicompue dl.newtop1i dl.nt1ineighave2 dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg d.receivedrrtot dl.newtop1i taxui ,  fe vce(cluster stnum)
eststo
xtreg  d.receivedrrtot  dl.newtop1i dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
xtreg  d.receivedrrtot  dl.newtop1i dl.nt1ineighave2 dl.bfavg dl.repcont l2.elect1 dl.lnrpcdinc dl.nonwhite dl.pop65 dl.uniondense dl.reserveratio taxui ,  re vce(cluster stnum) 
eststo
esttab using "/Users/thayes/Dropbox/Welfare Generosity & Inequality/data/uireceipttables2.rtf", replace label se starlevels(* .10 ** .05 *** .01) scalars(N )
